#ifndef __MyUtilsH__
#define __MyUtilsH__

#include <map>
#include <string>
#include <vector>

#define In
#define Out

namespace myutils
{
	const int BLOCKWIDTH = 25;
	const int BLOCKHEIGHT = 28;
	const int INTERVALWIDTH = 31;
	const int INTERVALHEIGHT = 35;
	const int BLOCKCOL = 19;
	const int BLOCKROW = 11;

	class LLKProcessor
	{
	public:
		LLKProcessor();
		~LLKProcessor();

		typedef std::string imgbuff;

		typedef struct position
		{
			long m_x;
			long m_y;
			bool m_valid;
			position(long x, long y)
			{
				m_x = x;
				m_y = y;
				m_valid = true;
			}
		}position, *LPposition;

		static const long byteperblock = 4 * myutils::BLOCKWIDTH * myutils::BLOCKHEIGHT;
		static const long offsetx = 30;
		static const long offsety = 190;

		HRESULT CopyWindowDCtoClipBoard(HWND hwnd);
		HRESULT PrintScreen(int offsetx, int offsety, HWND hwnd, bool savebmp = false);
		void TopmostWindow(HWND hwnd);
		void PrintMatrix();
		void ClearMatrixNMap();
		void LoadMetaImages();
		void PrintBMPMap();
		void TesetFunc();
		void TestCon(long x1, long y1, long x2, long y2);
		void Updateexevec();
		void TestExe();
		void TestClick();
		void ClickOnPos(long x1, long y1);
		void ExeAll();

	private:
		void SaveBMP(const char* filename, byte* bmpbuffer, BITMAPINFOHEADER bih, BITMAPFILEHEADER bfh);
		char GetBMPMapIndex(byte* bmpbuffer, BITMAPINFOHEADER bih, BITMAPFILEHEADER bfh);
		void UpdateMatrix(long row, long col, char value);
		void UpdateCharmap(char value, position pos);
		bool testConnectionX(long starty, long endy, long x1, long x2, Out long& y);
		bool testConnectionY(long startx, long endx, long y1, long y2, Out long& x);
		bool testConnection(long x1, long y1, long x2, long y2);
		char GetMatrixData(long row, long col);

		HWND m_hwnd;
		char* m_matrix;
		std::map<imgbuff, char> m_bmpmap;
		std::map< char, std::vector<position> > m_charmap;
		std::vector<position> m_exevec;
	};
}

#endif